/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ugc.cnel.manabi;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import oracle.toplink.essentials.jndi.JNDIConnector;
import oracle.toplink.essentials.sessions.Session;
import oracle.toplink.essentials.tools.sessionconfiguration.SessionCustomizer;

/**
 *
 * @author Admin
 */
public class ToplinkSessionCustomiser implements SessionCustomizer {

    /**
     * Get a dataSource connection and set it on the session with lookupType=STRING_LOOKUP
     */
    public void customize(Session session) throws Exception {
        JNDIConnector connector = null;
        DataSource dataSource = null;
        InitialContext initCxt = null;
        try {
            initCxt = new InitialContext();
// verify context
            if (initCxt != null) {
                dataSource = (DataSource) initCxt.lookup("java:/comp/env/jdbc/postgres");
            }
// get connector and modify the lookup type
            connector = (JNDIConnector) session.getLogin().getConnector();
            connector.setLookupType(JNDIConnector.STRING_LOOKUP);
        } catch (NamingException ex) {
            ex.printStackTrace();
        }
    }
}


